﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace OntologyFormDesigner.Widget
{
    public class WidgetForm : System.Windows.Forms.Form, OntologyUtility.Interfaces.IWidgetContainer 
    {
        public WidgetForm()
        {
            this.Widgets = new List<OntologyUtility.Interfaces.IWidget>();
            this.ViewerWidgets = new List<OntologyUtility.Interfaces.IWidgetViewer>();
        }

        public WidgetForm(System.Windows.Forms.Form form)
        {
            this.Widgets = new List<OntologyUtility.Interfaces.IWidget>();
            this.ViewerWidgets = new List<OntologyUtility.Interfaces.IWidgetViewer>();
            this.Text = form.Text;
            this.Name = form.Name;
            this.WidgetSize = new OntologyUtility.Xml.WidgetSize(form.Width, form.Height);
            this.WidgetLocation = new OntologyUtility.Xml.WidgetLocation(form.Location.X, form.Location.Y, form.Dock.ToString(), form.Anchor.ToString());
            this.
            Ontology = ((OntologyUtility.Xml.Ontology)form.Tag);
            foreach (Control control in form.Controls)
            {
                if (control is OntologyUtility.Interfaces.IWidget) 
                    this.Widgets.Add((OntologyUtility.Interfaces.IWidget)control);

                if (control is OntologyUtility.Interfaces.IWidgetViewer)
                    this.ViewerWidgets.Add((OntologyUtility.Interfaces.IWidgetViewer)control);
            }

        }
        protected OntologyUtility.Xml.Ontology ontology = null;
        public OntologyUtility.Xml.Ontology Ontology
        {
            get
            {
                return ontology;
            }
            set
            {
                this.ontology = value;
            }
        }

        protected List<OntologyUtility.Interfaces.IWidgetViewer> viewerWidgets = null;
        public List<OntologyUtility.Interfaces.IWidgetViewer> ViewerWidgets
        {
            get
            {
                return viewerWidgets;
            }
            set
            {
                this.viewerWidgets = value;
            }
        }

        protected List<OntologyUtility.Interfaces.IWidget> widgets = null;
        public List<OntologyUtility.Interfaces.IWidget> Widgets
        {
            get
            {
                return widgets;
            }
            set
            {
                this.widgets = value;
            }
        }

        protected OntologyUtility.Xml.Appearance apperance;
        public OntologyUtility.Xml.Appearance Appearance
        {
            get
            {
                if (apperance == null)
                {
                    String backColor = this.BackColor.R + "," + this.BackColor.G + "," + this.BackColor.B;
                    String foreColor = this.ForeColor.R + "," + this.ForeColor.G + "," + this.ForeColor.B;
                    String cursor = this.Cursor.ToString();
                    return new OntologyUtility.Xml.Appearance(backColor, foreColor, cursor);
                }
                return apperance;
            }
            set
            {
                apperance = value;
            }
        }

        protected OntologyUtility.Xml.WidgetFont font = null;
        public OntologyUtility.Xml.WidgetFont WidgetFont
        {
            get
            {
                return font;
                
            }
            set
            {
                this.font = value;
            }
        }

        protected OntologyUtility.Xml.WidgetLocation location = null;
        public OntologyUtility.Xml.WidgetLocation WidgetLocation
        {
            get
            {
                return location;
            }
            set
            {
                this.location = null;
            }
        }


        protected OntologyUtility.Xml.WidgetSize wSize = null;
        public OntologyUtility.Xml.WidgetSize WidgetSize
        {
            get
            {
                return wSize == null ? new OntologyUtility.Xml.WidgetSize(this.Width, this.Height) : wSize;
            }
            set
            {
                wSize = value;
            }
        }
    }
}
